@ebtalk as found here, you can use gparted for this:
*"So the best way I have found is to use GParted (you can either use a Linux-based OS, or boot from a GParted Live USB). It is simple enough to find detailed instructions on how to do each of these steps in detail, but here is the general method I have found to work:
Run GParted, find your SD card in the device list and shrink the main partition to as small as it will go.
Take the value of the last sector of this partition and multiply this by the sector size (512 for me; I presume this is standard, although you can check this in GParted settings for your device): this will give you the total size in bytes to copy.
Divide the total number of bytes by 4096 (round up if you need to - better to take a bit more space than not enough), and this will give you the 'count' to then enter into the following command at the terminal in a Linux environment (You can probably do this from the GParted Live USB operating system terminal or in Cygwin without sudo so long as you are running it as an administrator):
sudo dd if=/dev/mmcblk0 of=/path/to/your/file.img bs=4k count=<count>
Change the input device location if you need to. This should give you a final image file that is the smallest that it can be, omitting empty space."*